#ifndef _CACHE_H_
#define _CACHE_H_

#include "common.h"

void init_cache();

int read_cache_L1(hwaddr_t);
int read_cache_L2(hwaddr_t);

void write_cache_L1(hwaddr_t,size_t,uint32_t);
void write_cache_L2(hwaddr_t,size_t,uint32_t);

#define CACHE_BLOCK_BIT 6//64B
#define CACHE_L1_WAY_BIT 3//8路组相联
#define CACHE_L1_SET_BIT 7//128个line
#define CACHE_L2_WAY_BIT 4//16路组相联
#define CACHE_L2_SET_BIT 12
#define CACHE_L1_CAP (64*1024)//664KB
#define CACHE_L2_CAP (4*1024*1024)//4MB


#define CACHE_BLOCK_SIZE (1<<CACHE_BLOCK_BIT)
#define CACHE_L1_WAY_NUM (1<<CACHE_L1_WAY_BIT)
#define CACHE_L1_SET_NUM (1<<CACHE_L1_SET_BIT)

#define CACHE_L2_WAY_NUM (1<<CACHE_L2_WAY_BIT)
#define CACHE_L2_SET_NUM (1<<CACHE_L2_SET_BIT)

typedef struct 
{
    uint8_t data[CACHE_BLOCK_SIZE];
    uint32_t tag;
    bool validVal;
}L1;

L1 cache_L1[CACHE_L1_SET_NUM*CACHE_L1_WAY_NUM];

typedef struct 
{
    uint8_t data[CACHE_BLOCK_SIZE];
    uint32_t tag;
    bool validVal;
    bool dirtyVal;
}L2;

L2 cache_L2[CACHE_L2_SET_NUM*CACHE_L2_WAY_NUM];

#endif
